#!/usr/bin/bash -e

# Copyright 2014, 2015 Endless Mobile, Inc.

# This file is part of eos-event-recorder-daemon.
#
# eos-event-recorder-daemon is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or (at your
# option) any later version.
#
# eos-event-recorder-daemon is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with eos-event-recorder-daemon.  If not, see
# <http://www.gnu.org/licenses/>.

if [ ! -f /etc/metrics/eos-metrics-permissions.conf ]; then
    echo "Configuration file at /etc/metrics/eos-metrics-permissions.conf not found or permission denied." >&2
    exit 1
fi

ENVIRONMENT="$1"
if [ "$ENVIRONMENT" == "dev" ] || [ "$ENVIRONMENT" == "test" ] || [ "$ENVIRONMENT" == "production" ]; then
    sed --in-place "s/\(environment *= *\).*/\1"$ENVIRONMENT"/" /etc/metrics/eos-metrics-permissions.conf
else
    echo "Invalid environment "$ENVIRONMENT" passed in as parameter." >&2
    exit 2
fi
